/**
 * 操作日志实体类 - 系统操作审计和安全追踪的核心实体
 *
 * 开发人员：陈宏伟
 * 开发时间：2025-10-20 至 2025-10-25
 * 模块职责：定义系统操作日志的基本信息和业务属性，支持完整的操作审计和安全追踪功能
 *
 * 技术要点：
 * - 多租户关联设计，与企业、用户实体关联
 * - 操作行为和资源类型追踪记录
 * - 请求上下文信息采集和IP追踪
 * - JSON格式的详细信息存储
 * - 审计字段自动维护操作时间
 *
 * 开发故事：负责操作日志实体的数据模型设计，与审计日志切面深度配合，实现系统操作的完整审计和安全追踪能力。
 */
package com.pbl.entity;

import lombok.*;

import javax.persistence.*;
import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "operation_logs")
public class OperationLog {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "enterprise_id", nullable = false)
    private Enterprise enterprise;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;

    @Column(nullable = false, length = 64)
    private String action;

    @Column(name = "resource_type", length = 64)
    private String resourceType;

    @Column(name = "resource_id", length = 64)
    private String resourceId;

    @Column(name = "request_id", length = 64)
    private String requestId;

    @Column(length = 45)
    private String ip;

    @Column(name = "user_agent", length = 255)
    private String userAgent;

    @Column(name = "detail", columnDefinition = "TEXT")
    private String detail; // JSON text

    @Column(name = "created_at", insertable = false, updatable = false)
    private LocalDateTime createdAt;
}
